<template>
  <template v-for="(item, index) in props.metaData" :key="index">
    <el-menu-item
      :index="`${props.index}-${item.meta.id}`"
      v-if="!item.children || item.children.length == 0"
      :key="`${props.index}-${item.meta.id}`"
      @click="handelClick(item,`${props.index}-${item.meta.id}`)"
    >
      <el-icon size="20"><component :is="item.meta.icon"></component></el-icon>
      <span>{{ item.meta.name }}</span>
    </el-menu-item>
    <el-sub-menu :index="`${props.index}-${item.meta.id}`" v-else>
      <template #title>
        <el-icon size="20"
          ><component :is="item.meta.icon"></component
        ></el-icon>
        <span>{{ item.meta.name }}</span>
      </template>
      <Tree-menu
        :index="`${props.index}-${item.meta.id}`"
        :metaData="item.children"
      ></Tree-menu>
    </el-sub-menu>
  </template>
</template>

<script setup>
import useMenuStore from "@/stores/Menu";
import { defineProps } from "vue";
import { useRouter } from "vue-router";
const router=useRouter()
const props = defineProps({
  metaData: {
    type: Object,
  },
  index: {},
});
const MenuStore=useMenuStore()
// 点击菜单
const handelClick=(item,index)=>{
  console.log(item);
  console.log(index);
  
  router.push(item.meta.path)
  MenuStore.addMenu(item.meta)
  MenuStore.changeActive(index)

}
console.log(props.index);

console.log(props.metaData);
</script>

<style scoped></style>
